import os
from threading import Thread
import cv2, time


class VideoStreamWidget(object):
    def __init__(self, src=0):
        filepath = r"C:\Users\itork\Desktop\zl-test\case\9-22\4\Camera\VID_20210923_184210.mp4"
        self.capture = cv2.VideoCapture(filepath)
        # Start the thread to read frames from the video stream
        self.thread = Thread(target=self.update, args=())
        self.thread.daemon = True
        self.thread.start()

    interval = []

    def update(self):

        # Read the next frame from the stream in a different thread
        while True:
            if self.capture.isOpened():
                (self.status, self.frame) = self.capture.read()
                # 获取每帧时间戳
                cur = self.capture.get(cv2.CAP_PROP_POS_MSEC)
                # 计算每帧
                super.interval.append(float((cur - pre) / 1000))
                pre = cur
        print(self.interval)

    def show_frame(self):
        print(self.interval)
        # print(self.capture.get(cv2.CAP_PROP_POS_MSEC))
        # # Display frames in main program
        # cv2.imshow('frame', self.frame)
        # key = cv2.waitKey(1)
        # if key == ord('q'):
        #     self.capture.release()
        #     cv2.destroyAllWindows()
        #     exit(1)


if __name__ == '__main__':
    video_stream_widget = VideoStreamWidget()
    video_stream_widget.show_frame()
